package org.jeecg.config.sharding;

import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;

@Slf4j
@Component
public class UserAlgorithm implements PreciseShardingAlgorithm<Date> {

    private SimpleDateFormat dateformat = new SimpleDateFormat("yyyyMM");
    @Override
    public String doSharding(Collection<String> tableNames, PreciseShardingValue<Date> preciseShardingValue) {
        StringBuffer tableName = new StringBuffer();
      //  log.info("执行操作的表名{}",preciseShardingValue.getLogicTableName() + dateformat.format(preciseShardingValue.getValue()));
        tableName.append(preciseShardingValue.getLogicTableName()).append(dateformat.format(preciseShardingValue.getValue()));
        return tableName.toString();

    }
}